﻿using System;
using System.Collections.Generic;
using System.Web;
using ZX.Web.UI.Controls;
using ZX.BLL.Extend;
using ZX.Common;
using ZX.BLL;
using ZX.SYS.Library;
using ZX.CRM.Library;
using System.Collections;
namespace ZX.WebApp.Crm.Common
{

    public partial class DataProcessin : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = this.GetStringFromQueryString("action", "");
            switch (action.ToLower())
            {

                case "save":
                    Save();
                    break;
                case "get":
                    Get();
                    break;
            }
        }
        private void Save()
        {
            string strEntity = this.GetStringFromQueryString("entity", "");
            switch (strEntity.ToLower())
            {
                case "crmproductlayoutrole":
                    SaveCrmProductLayoutRole();
                    break;
            }

        }

        //保存产品规划角色
        private void SaveCrmProductLayoutRole()
        {
            
            BaseBussnies bll = new BaseBussnies();
            //需要移动的部门ID集合
            string[] userIds = ZXContext.Request.Form["userDataContent"].ToString().Split(',');
            string  json = ZXContext.Request.Form["jsonDataContent"].ToString();
            string strJson = json.Replace("[@@]", "\\");
            try
            {
                CrmProductLayoutRole instance = (CrmProductLayoutRole)Globals.JSONtoObject("CrmProductLayoutRole", strJson);
                foreach (string userId in userIds)
                {
                    CrmProductLayoutRole role = new CrmProductLayoutRole();
                    role.ID = Guid.NewGuid();
                    role.ProductLayoutId = instance.ProductLayoutId;
                    role.ProductRoleID = instance.ProductRoleID;
                    role.Explain = instance.Explain;
                    instance.UserId = new Guid(userId);
                    bll.Insert(instance);
                }
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        #region 获取数据
        private void Get()
        {
           string entityName = this.GetStringFromQueryString("entity", "");
           switch (entityName.ToLower())
           {
               case "productrole": GetProductRole();
                   break;
           }
        }
        //获取产品角色
        private void GetProductRole()
        {
            BDatPhraseDetail datPhrase = new BDatPhraseDetail();
            IList<DatPhraseDetail> dutyType = datPhrase.GetDatPhraseDetailByClassValue("ProductLayOutRole");
            string listjson = Globals.getJSON<DatPhraseDetail>(dutyType);
            HttpContext.Current.Response.Write(listjson);
        }
        #endregion
    }

}